package redis

import (
	"fmt"
	"github.com/go-redis/redis"
	"github.com/spf13/viper"
)

var (
	Client *redis.Client
)

// Init 初始化 Redis 链接
func Init() (err error) {
	Client = redis.NewClient(&redis.Options{
		Addr: fmt.Sprintf("%s:%d",
			viper.GetString("redis.host"),
			viper.GetInt("redis.port")),
		DB: viper.GetInt("redis.db"), // use default DB
	})
	_, err = Client.Ping().Result()
	return
}
